package com.wayhome.srpingbootmybatis.doctor.service;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy;
import com.wayhome.srpingbootmybatis.doctor.entity.DrScoreOptinsDTO;
import com.wayhome.srpingbootmybatis.doctor.mapper.ImsDocMapper;
import com.wayhome.srpingbootmybatis.mbs.expertimport.dto.ExpertTemplate;
import com.wayhome.srpingbootmybatis.mbs.expertimport.dto.SetlTldyExportDTO;
import com.wayhome.srpingbootmybatis.mbs.util.HeadContentCellStyle;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.util.IOUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

@Service
@Slf4j
public class DrScoreClrOptinsService {

    @Resource
    private ImsDocMapper imsDocMapper;

    public void exportDrScoreInfoClrOptions(MultipartFile file, HttpServletResponse response) throws IOException {

        DrScoreOptinsImptListener drScoreOptinsImptListener = new DrScoreOptinsImptListener(imsDocMapper);

        InputStream inputStream = file.getInputStream();
        EasyExcel.read(inputStream, DrScoreOptinsDTO.class, drScoreOptinsImptListener).sheet().doRead();

        List<DrScoreOptinsDTO> list = drScoreOptinsImptListener.list;

        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8");
        response.addHeader("Content-Disposition", "attachment;filename=template.xlsx");
        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + "" + ".xlsx"); // 设置响应头
        EasyExcel.write(response.getOutputStream(), DrScoreOptinsDTO.class)
                .sheet("违规单据=清算经办机构处理")
                .registerWriteHandler(HeadContentCellStyle.myHorizontalCellStyleStrategy())
                .registerWriteHandler(new SimpleColumnWidthStyleStrategy(20))
                .doWrite(list);
    }
}
